/**
 * 区域region.js
 * 版本号： v1.0.0
 */
$(function(){
    var lastChecked = null;
    $("#region_dataList").treegrid({
        fitColumns: true,
        fit:true,
        method: "POST",
        rownumbers: true,
        singleSelect:true,
        border: false,
        striped:true,
        url: CONTEXT_PATH + '/region/getTreeRegion.do',
        idField: 'regionId',
        treeField: "province",
        frozenColumns:[[
            {field:'regionId',checkbox:true}
        ]],
        columns: [
            [
                {field: 'province', title: '区域名称', width: 220, align: 'left', fixed: true},
                {field: 'regionStatus', title: '区域状态', width: 80, align: 'left', formatter:function(val){
                        if(val == 0) return "<span style='color: green; font-weight: bold'>启用</span>";
                        if(val == 1) return "<span style='color: red; font-weight: bold'>禁止</span>";
                }}
            ]
        ],
        onBeforeExpand: function (row) {   //展开父节点根据Id进行异步加载
            $(this).treegrid('options').url = CONTEXT_PATH + '/region/getTreeDistrict.do?regionId=' + row.regionId;
        },
        onCheck:function(rowIndex, rowData){
            var row = $("#region_dataList").treegrid("getChecked");
            if(row && rowIndex == lastChecked){
                $('#region_dataList').treegrid("unselectAll");//取消选中当前所有行
                lastChecked = null;
            }else{
                lastChecked = rowIndex;
            }
        },
        onLoadSuccess:function(row, data){
            if(data.length > 0){
                $("#region_dataList").treegrid("select", data[0].regionId);
            }
        }
    });

});


